/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.util.ArrayList;

/**
 *
 * @author Eduardo
 */
public class CadastroConvenio extends javax.swing.JDialog {

//    /**
//     * Creates new form CadastroMensalista
//     */
//    public CadastroConvenio() {
//        initComponents();
//        setModal(true);
//        msgErro.setVisible(false);
//        atualizaTabela();
//    }
//
//    public static void atualizaTabela() {
//        ArrayList<Mensalista> m = Recuperadora.recMensalista();
//        Object[][] tabela = new Object[m.size()][3];
//        for (int i = 0; i < m.size(); i++) {
//            tabela[i][0] = m.get(i).getCodigo();
//            tabela[i][1] = m.get(i).getNome();
//            tabela[i][2] = m.get(i).getCelular();
//        }
//
//        tabelaMens.setModel(new javax.swing.table.DefaultTableModel(tabela,
//                new String[]{
//                    "Código", "Nome do Cliente", "Celular"
//                }) {
//
//            Class[] types = new Class[]{
//                java.lang.String.class, java.lang.String.class, java.lang.String.class
//            };
//            boolean[] canEdit = new boolean[]{
//                false, false, false
//            };
//
//            public Class getColumnClass(int columnIndex) {
//                return types[columnIndex];
//            }
//
//            public boolean isCellEditable(int rowIndex, int columnIndex) {
//                return canEdit[columnIndex];
//            }
//        });
//        tabelaMens.repaint();
//    }
//
//    /**
//     * This method is called from within the constructor to initialize the form.
//     * WARNING: Do NOT modify this code. The content of this method is always
//     * regenerated by the Form Editor.
//     */
//    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tabelaMens = new javax.swing.JTable();
        msgErro = new javax.swing.JLabel();
        botaoIncluirAtiv = new javax.swing.JButton();
        botaoRemoveAtiv = new javax.swing.JButton();
        botaoAlteraAtiv = new javax.swing.JButton();
        textoTituloJanela = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de Clientes Mensalistas - Power Park");
        setResizable(false);

        tabelaMens.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Nome"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabelaMens.setColumnSelectionAllowed(true);
        tabelaMens.getTableHeader().setReorderingAllowed(false);
        tabelaMens.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaMensMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tabelaMens);
        tabelaMens.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tabelaMens.getColumnModel().getColumn(0).setMinWidth(70);
        tabelaMens.getColumnModel().getColumn(0).setPreferredWidth(70);
        tabelaMens.getColumnModel().getColumn(0).setMaxWidth(70);

        msgErro.setFont(new java.awt.Font("Tahoma", 1, 10)); // NOI18N
        msgErro.setForeground(new java.awt.Color(255, 0, 0));
        msgErro.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        msgErro.setText("Selecione algum item na tabela");

        botaoIncluirAtiv.setText("Incluir Novo Convênio");
        botaoIncluirAtiv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoIncluirAtivActionPerformed(evt);
            }
        });

        botaoRemoveAtiv.setText("Excluir Convênio Selecionado");
        botaoRemoveAtiv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoRemoveAtivActionPerformed(evt);
            }
        });

        botaoAlteraAtiv.setText("Editar Tabela de Preços do Convênio");
        botaoAlteraAtiv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoAlteraAtivActionPerformed(evt);
            }
        });

        textoTituloJanela.setFont(new java.awt.Font("Calibri", 1, 14)); // NOI18N
        textoTituloJanela.setText("Cadastro de Convênios");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textoTituloJanela)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 333, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(botaoAlteraAtiv, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(botaoRemoveAtiv, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(botaoIncluirAtiv, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(msgErro, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(msgErro)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoIncluirAtiv)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoRemoveAtiv)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoAlteraAtiv)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(textoTituloJanela, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(72, 72, 72))))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-586)/2, (screenSize.height-343)/2, 586, 343);
    }// </editor-fold>//GEN-END:initComponents

    private void tabelaMensMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaMensMouseClicked
        msgErro.setVisible(false);
    }//GEN-LAST:event_tabelaMensMouseClicked

    private void botaoIncluirAtivActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoIncluirAtivActionPerformed
        msgErro.setVisible(false);
        NovoConvenio i1 = new NovoConvenio();
        i1.setVisible(true);
        i1.repaint();
    }//GEN-LAST:event_botaoIncluirAtivActionPerformed

    private void botaoAlteraAtivActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoAlteraAtivActionPerformed
        int linha = tabelaMens.getSelectedRow();
        if (linha >= 0) {
            int codAtiv = Integer.parseInt(tabelaMens.getModel().getValueAt(linha, 0).toString());
            NovoConvenio i1 = new NovoConvenio();
            i1.setVisible(true);
            i1.repaint();
        } else {
            msgErro.setVisible(true);
        }
    }//GEN-LAST:event_botaoAlteraAtivActionPerformed

    private void botaoRemoveAtivActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoRemoveAtivActionPerformed
//        ArrayList<Mensalista> m = Recuperadora.recMensalista();
//        if (tabelaMens.getSelectedRow() >= 0) {
//            int cod = Integer.valueOf(tabelaMens.getValueAt(tabelaMens.getSelectedRow(), 0).toString());
//            for (int i = 0; i < m.size(); i++) {
//                if (Integer.valueOf(m.get(i).getCodigo()) == cod) {
//                    cod = i;
//                    break;
//                }
//            }
//            m.remove(cod);
//            Salvadora.salvaMensalista(m);
//            atualizaTabela();
//        } else {
//            msgErro.setVisible(true);
//        }
    }//GEN-LAST:event_botaoRemoveAtivActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoAlteraAtiv;
    private javax.swing.JButton botaoIncluirAtiv;
    private javax.swing.JButton botaoRemoveAtiv;
    private javax.swing.JScrollPane jScrollPane1;
    private static javax.swing.JLabel msgErro;
    private static javax.swing.JTable tabelaMens;
    private javax.swing.JLabel textoTituloJanela;
    // End of variables declaration//GEN-END:variables
}
